//
//  MYNewsCategoryCell.m
//  MuYing
//
//  Created by tbb on 2019/8/2.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "MYNewsCategoryCell.h"
#import "MYNewsRankVC.h"
#import "MYNewsHotelSearchVC.h"
#import "MYNewsParentingSearchVC.h"
#import "MYNewsActionSearchVC.h"
#import "MYNewsHotActionSearchVC.h"
@interface MYNewsCategoryCell ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView * categoryCollView;
@property (nonatomic, copy) NSArray * iconArr;
@property (nonatomic, copy) NSArray * titleArr;
@end

@implementation MYNewsCategoryCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.iconArr = @[@"news_class_ranking_icon",
        @"news_Class_Parenting_icon",
        @"news_Class_Scenicspot_icon",
        @"news_Class_Action_icon",
        @"news_Class_HotAction_icon",
        @"news_Class_Evaluation_icon",
        @"news_Class_Recommend_icon",
        @"news_Class_children_icon"];
        self.titleArr = @[kYQLS(@"排行榜"),
        kYQLS(@"亲子酒店"),
        kYQLS(@"景点"),
        kYQLS(@"活动/兴趣班"),
        kYQLS(@"最新热话"),
        kYQLS(@"测评"),
        kYQLS(@"好物推荐"),
        kYQLS(@"育儿话题")];
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.contentView.backgroundColor = UIColor.whiteColor;//HexColor(0xFAFAFA);
    [self.contentView addSubview:self.categoryCollView];
    [self.categoryCollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(27);
        make.right.mas_equalTo(-27);
        make.top.mas_equalTo(12);
        make.bottom.mas_equalTo(-44);
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

#pragma makr -- lazy
-(UICollectionView *) categoryCollView{
    if (!_categoryCollView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        layout.minimumLineSpacing = 18;
        CGFloat cw = floor((((kScreenWidth - 54) - 260) / 3.0));
        layout.minimumInteritemSpacing = cw;
        layout.itemSize = CGSizeMake(65, 69);
        _categoryCollView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _categoryCollView.delegate = self;
        _categoryCollView.dataSource = self;
        _categoryCollView.bounces = false;
        _categoryCollView.showsVerticalScrollIndicator = NO;
        _categoryCollView.backgroundColor = UIColor.whiteColor;//HexColor(0xFAFAFA);
        [_categoryCollView registerNib:[UINib nibWithNibName:@"MYNewsCategoryCollViewCell" bundle:nil] forCellWithReuseIdentifier:@"MYNewsCategoryCollViewCell"];
    }
    return _categoryCollView;
}
#pragma makr -- lazy end

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.iconArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    MYNewsCategoryCollViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MYNewsCategoryCollViewCell" forIndexPath:indexPath];
    cell.categoryIcon.image = YQIMG(self.iconArr[indexPath.item]);
    cell.titleLb.text = self.titleArr[indexPath.item];
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    /*if (indexPath.item == 0) {
        MYNewsRankVC *rankVC = [[MYNewsRankVC alloc] init];
        [self.YQViewController.navigationController pushViewController:rankVC animated:true];
    }else if (indexPath.item == 5) {
        MYNewsHotelSearchVC *hotelSearchVC = [[MYNewsHotelSearchVC alloc] init];
        hotelSearchVC.categoryId = @"1";
        [self.YQViewController.navigationController pushViewController:hotelSearchVC animated:true];
    }else if (indexPath.item == 6) {
        MYNewsParentingSearchVC *parentingSearchVC = [[MYNewsParentingSearchVC alloc] init];
        parentingSearchVC.categoryId = @"2";
        [self.YQViewController.navigationController pushViewController:parentingSearchVC animated:true];
    }else if(indexPath.item == 7) {
        MYNewsActionSearchVC *actionSearchVC = [[MYNewsActionSearchVC alloc] init];
        actionSearchVC.categoryId = @"3";
        [self.YQViewController.navigationController pushViewController:actionSearchVC animated:true];
    }else{
        MYNewsHotActionSearchVC *hotActionSearch = [[MYNewsHotActionSearchVC alloc] init];
        NSString *categoryId = @"";
        if (indexPath.row == 1) {
            categoryId = @"4";
        }else if (indexPath.row == 2){
            categoryId = @"5";
        }else if (indexPath.row == 3){
            categoryId = @"7";
        }else if (indexPath.row == 4) {
            categoryId = @"6";
        }
        hotActionSearch.categoryId = categoryId;//[NSString stringWithFormat:@"%zd",indexPath.item];
        [self.YQViewController.navigationController pushViewController:hotActionSearch animated:true];
    }*/
    if (indexPath.item == 0) {
        MYNewsRankVC *rankVC = [[MYNewsRankVC alloc] init];
        [self.YQViewController.navigationController pushViewController:rankVC animated:true];
    }else if (indexPath.item == 1) {
        MYNewsHotelSearchVC *hotelSearchVC = [[MYNewsHotelSearchVC alloc] init];
        hotelSearchVC.categoryId = @"1";

        [self.YQViewController.navigationController pushViewController:hotelSearchVC animated:true];
    }else if (indexPath.item == 2) {
        MYNewsParentingSearchVC *parentingSearchVC = [[MYNewsParentingSearchVC alloc] init];
        parentingSearchVC.categoryId = @"2";

        [self.YQViewController.navigationController pushViewController:parentingSearchVC animated:true];
    }else if(indexPath.item == 3) {
        MYNewsActionSearchVC *actionSearchVC = [[MYNewsActionSearchVC alloc] init];
        actionSearchVC.categoryId = @"3";

        [self.YQViewController.navigationController pushViewController:actionSearchVC animated:true];
    }else if(indexPath.item == 5) {
        MYNewsHotActionSearchVC *hotActionSearch = [[MYNewsHotActionSearchVC alloc] init];
        NSString *categoryId = @"";
        if (indexPath.row == 1) {
            categoryId = @"4";
        }else if (indexPath.row == 2){
            categoryId = @"5";
        }else if (indexPath.row == 3){
            categoryId = @"7";
        }else if (indexPath.row == 4) {
            categoryId = @"6";
        }
        hotActionSearch.categoryId = categoryId;//[NSString stringWithFormat:@"%zd",indexPath.item];
        [self.YQViewController.navigationController pushViewController:hotActionSearch animated:true];
    }else{
        MYNewsHotActionSearchVC *hotActionSearch = [[MYNewsHotActionSearchVC alloc] init];
        NSString *categoryId = @"";
        if (indexPath.row == 1) {
            categoryId = @"4";
        }else if (indexPath.row == 2){
            categoryId = @"5";
        }else if (indexPath.row == 3){
            categoryId = @"7";
        }else if (indexPath.row == 4) {
            categoryId = @"6";
        }
        hotActionSearch.categoryId = categoryId;//[NSString stringWithFormat:@"%zd",indexPath.item];
        [self.YQViewController.navigationController pushViewController:hotActionSearch animated:true];
    }

}
@end

